<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简历上传解析 - 前端演示</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 15px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        
        .header {
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
            padding: 30px;
            text-align: center;
        }
        
        .header h1 {
            font-size: 2.5em;
            margin-bottom: 10px;
        }
        
        .header p {
            font-size: 1.2em;
            opacity: 0.9;
        }
        
        .content {
            padding: 40px;
        }
        
        .upload-area {
            border: 3px dashed #ddd;
            border-radius: 10px;
            padding: 40px;
            text-align: center;
            margin-bottom: 30px;
            transition: all 0.3s ease;
            cursor: pointer;
        }
        
        .upload-area:hover {
            border-color: #667eea;
            background-color: #f8f9ff;
        }
        
        .upload-area.dragover {
            border-color: #667eea;
            background-color: #f0f4ff;
            transform: scale(1.02);
        }
        
        .upload-icon {
            font-size: 3em;
            color: #667eea;
            margin-bottom: 20px;
        }
        
        .file-input {
            display: none;
        }
        
        .upload-text {
            font-size: 1.2em;
            color: #666;
            margin-bottom: 15px;
        }
        
        .file-info {
            background: #f8f9fa;
            border-radius: 8px;
            padding: 15px;
            margin: 20px 0;
            display: none;
        }
        
        .btn {
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
            border: none;
            padding: 12px 30px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 16px;
            margin: 10px;
            transition: all 0.3s ease;
        }
        
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        
        .btn:disabled {
            background: #6c757d;
            cursor: not-allowed;
            transform: none;
        }
        
        .btn-secondary {
            background: linear-gradient(45deg, #28a745, #20c997);
        }
        
        .loading {
            display: none;
            text-align: center;
            padding: 30px;
        }
        
        .spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #667eea;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .result-area {
            margin-top: 30px;
            display: none;
        }
        
        .result-card {
            background: #f8f9fa;
            border-radius: 10px;
            padding: 25px;
            margin: 20px 0;
            border-left: 5px solid #667eea;
        }
        
        .result-card.success {
            border-left-color: #28a745;
            background: #d4edda;
        }
        
        .result-card.error {
            border-left-color: #dc3545;
            background: #f8d7da;
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin: 25px 0;
        }
        
        .stat-card {
            background: white;
            border-radius: 8px;
            padding: 20px;
            text-align: center;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .stat-number {
            font-size: 2em;
            font-weight: bold;
            color: #667eea;
            margin-bottom: 5px;
        }
        
        .stat-label {
            color: #666;
            font-size: 0.9em;
        }
        
        .skills-section {
            margin: 25px 0;
        }
        
        .skills-category {
            margin: 15px 0;
        }
        
        .skills-category h4 {
            color: #495057;
            margin-bottom: 10px;
        }
        
        .skills-list {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }
        
        .skill-tag {
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
            padding: 5px 15px;
            border-radius: 20px;
            font-size: 14px;
            box-shadow: 0 2px 5px rgba(102, 126, 234, 0.3);
        }
        
        .content-preview {
            background: #f8f9fa;
            border-radius: 8px;
            padding: 20px;
            max-height: 300px;
            overflow-y: auto;
            white-space: pre-wrap;
            font-family: 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.5;
        }
        
        .api-info {
            background: #e9ecef;
            border-radius: 8px;
            padding: 20px;
            margin: 30px 0;
        }
        
        .api-info code {
            background: #f8f9fa;
            padding: 2px 6px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
        }
        
        .tab-container {
            margin: 30px 0;
        }
        
        .tab-buttons {
            display: flex;
            border-bottom: 2px solid #eee;
        }
        
        .tab-button {
            background: none;
            border: none;
            padding: 15px 25px;
            cursor: pointer;
            font-size: 16px;
            color: #666;
            border-bottom: 3px solid transparent;
            transition: all 0.3s ease;
        }
        
        .tab-button.active {
            color: #667eea;
            border-bottom-color: #667eea;
        }
        
        .tab-content {
            display: none;
            padding: 25px 0;
        }
        
        .tab-content.active {
            display: block;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>📄 简历上传解析系统</h1>
            <p>支持PDF、Word、TXT格式 | 智能提取关键信息 | API接口演示</p>
        </div>
        
        <div class="content">
            <div class="api-info">
                <h3>🔗 API接口信息</h3>
                <p><strong>完整版:</strong> <code>POST /api/resume/upload/</code></p>
                <p><strong>简化版:</strong> <code>POST /api/resume/upload/simple/</code></p>
                <p><strong>支持格式:</strong> PDF, Word (.doc/.docx), TXT | <strong>最大文件:</strong> 10MB</p>
            </div>
            
            <div class="upload-area" id="uploadArea">
                <div class="upload-icon">📁</div>
                <div class="upload-text">
                    <strong>点击选择文件</strong> 或 <strong>拖拽文件到此处</strong><br>
                    支持 PDF、Word、TXT 格式
                </div>
                <input type="file" id="fileInput" class="file-input" accept=".pdf,.doc,.docx,.txt">
            </div>
            
            <div class="file-info" id="fileInfo">
                <h4>📋 选中文件信息</h4>
                <p id="fileDetails"></p>
            </div>
            
            <div style="text-align: center;">
                <button class="btn" id="uploadBtn" onclick="uploadFile(false)" disabled>
                    🔍 使用完整版API解析
                </button>
                <button class="btn btn-secondary" id="uploadSimpleBtn" onclick="uploadFile(true)" disabled>
                    📝 使用简化版API解析
                </button>
            </div>
            
            <div class="loading" id="loading">
                <div class="spinner"></div>
                <p>正在解析文件，请稍候...</p>
            </div>
            
            <div class="result-area" id="resultArea">
                <div class="tab-container">
                    <div class="tab-buttons">
                        <button class="tab-button active" onclick="showTab('overview')">📊 概览</button>
                        <button class="tab-button" onclick="showTab('details')">📋 详细信息</button>
                        <button class="tab-button" onclick="showTab('content')">📄 原始内容</button>
                    </div>
                    
                    <div class="tab-content active" id="overviewTab">
                        <div id="overviewContent"></div>
                    </div>
                    
                    <div class="tab-content" id="detailsTab">
                        <div id="detailsContent"></div>
                    </div>
                    
                    <div class="tab-content" id="contentTab">
                        <div id="contentPreview"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        let selectedFile = null;
        
        // 初始化事件监听
        document.addEventListener('DOMContentLoaded', function() {
            const uploadArea = document.getElementById('uploadArea');
            const fileInput = document.getElementById('fileInput');
            
            // 点击上传区域选择文件
            uploadArea.addEventListener('click', () => fileInput.click());
            
            // 文件选择事件
            fileInput.addEventListener('change', handleFileSelect);
            
            // 拖拽事件
            uploadArea.addEventListener('dragover', handleDragOver);
            uploadArea.addEventListener('dragleave', handleDragLeave);
            uploadArea.addEventListener('drop', handleDrop);
        });
        
        function handleFileSelect(event) {
            const file = event.target.files[0];
            if (file) {
                selectedFile = file;
                showFileInfo(file);
                enableUploadButtons();
            }
        }
        
        function handleDragOver(event) {
            event.preventDefault();
            document.getElementById('uploadArea').classList.add('dragover');
        }
        
        function handleDragLeave(event) {
            event.preventDefault();
            document.getElementById('uploadArea').classList.remove('dragover');
        }
        
        function handleDrop(event) {
            event.preventDefault();
            document.getElementById('uploadArea').classList.remove('dragover');
            
            const files = event.dataTransfer.files;
            if (files.length > 0) {
                selectedFile = files[0];
                showFileInfo(files[0]);
                enableUploadButtons();
            }
        }
        
        function showFileInfo(file) {
            const fileInfo = document.getElementById('fileInfo');
            const fileDetails = document.getElementById('fileDetails');
            
            fileDetails.innerHTML = `
                <strong>文件名:</strong> ${file.name}<br>
                <strong>文件大小:</strong> ${formatFileSize(file.size)}<br>
                <strong>文件类型:</strong> ${file.type || '未知'}<br>
                <strong>最后修改:</strong> ${new Date(file.lastModified).toLocaleString()}
            `;
            
            fileInfo.style.display = 'block';
        }
        
        function enableUploadButtons() {
            document.getElementById('uploadBtn').disabled = false;
            document.getElementById('uploadSimpleBtn').disabled = false;
        }
        
        function uploadFile(useSimpleAPI) {
            if (!selectedFile) {
                alert('请先选择文件');
                return;
            }
            
            // 显示加载状态
            document.getElementById('loading').style.display = 'block';
            document.getElementById('resultArea').style.display = 'none';
            
            // 模拟API请求（实际使用时替换为真实API）
            setTimeout(() => {
                simulateAPIResponse(useSimpleAPI);
            }, 2000);
        }
        
        function simulateAPIResponse(isSimpleAPI) {
            // 隐藏加载状态
            document.getElementById('loading').style.display = 'none';
            
            // 模拟API响应数据
            const mockResponse = {
                success: true,
                message: "简历解析成功",
                data: {
                    file_info: {
                        original_filename: selectedFile.name,
                        file_size: selectedFile.size,
                        file_extension: selectedFile.name.split('.').pop(),
                        content_length: 850
                    },
                    raw_content: `张三简历\n\n基本信息：\n姓名：张三\n工作经验：5年\n教育：本科计算机科学\n地点：北京\n期望薪资：20000-25000\n\n技能：\n- 编程语言：Python, Java, JavaScript, TypeScript\n- 框架：Django, Spring Boot, React, Vue.js\n- 数据库：MySQL, PostgreSQL, Redis, MongoDB\n- 工具：Git, Docker, Kubernetes, Jenkins\n- 云服务：AWS, Azure\n\n工作经历：\n2019-2024 高级软件开发工程师\n- 负责微服务架构设计和开发\n- 团队技术负责人，管理5人开发团队\n- 优化系统性能，提升响应速度50%\n\n项目经验：\n1. 电商平台后端系统\n2. 用户画像分析系统\n3. 实时数据处理平台`,
                    key_info: {
                        experience_years: 5,
                        skills: {
                            all_skills: ["Python", "Java", "JavaScript", "TypeScript", "Django", "Spring Boot", "React", "Vue.js", "MySQL", "PostgreSQL", "Redis", "MongoDB", "Git", "Docker", "Kubernetes", "Jenkins", "AWS", "Azure"],
                            programming_languages: ["Python", "Java", "JavaScript", "TypeScript"],
                            frameworks: ["Django", "Spring Boot", "React", "Vue.js"],
                            databases: ["MySQL", "PostgreSQL", "Redis", "MongoDB"],
                            tools: ["Git", "Docker", "Kubernetes", "Jenkins", "AWS", "Azure"]
                        },
                        education: "本科",
                        preferred_location: "北京",
                        expected_salary: "20000-25000",
                        resume_length: 850
                    }
                }
            };
            
            displayResult(mockResponse, isSimpleAPI);
        }
        
        function displayResult(data, isSimpleAPI) {
            document.getElementById('resultArea').style.display = 'block';
            
            if (data.success) {
                if (isSimpleAPI) {
                    displaySimpleResult(data);
                } else {
                    displayCompleteResult(data);
                }
            } else {
                displayError(data);
            }
        }
        
        function displayCompleteResult(data) {
            const keyInfo = data.data.key_info;
            
            // 概览标签
            document.getElementById('overviewContent').innerHTML = `
                <div class="result-card success">
                    <h3>✅ ${data.message}</h3>
                </div>
                
                <div class="stats-grid">
                    <div class="stat-card">
                        <div class="stat-number">${keyInfo.experience_years}</div>
                        <div class="stat-label">工作经验 (年)</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-number">${keyInfo.skills.all_skills.length}</div>
                        <div class="stat-label">技能总数</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-number">${keyInfo.skills.programming_languages.length}</div>
                        <div class="stat-label">编程语言</div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-number">${data.data.file_info.content_length}</div>
                        <div class="stat-label">文档字符数</div>
                    </div>
                </div>
                
                <div class="result-card">
                    <h4>🎯 基本信息</h4>
                    <p><strong>教育背景:</strong> ${keyInfo.education}</p>
                    <p><strong>期望地点:</strong> ${keyInfo.preferred_location}</p>
                    <p><strong>期望薪资:</strong> ${keyInfo.expected_salary}</p>
                </div>
            `;
            
            // 详细信息标签
            document.getElementById('detailsContent').innerHTML = `
                <div class="result-card">
                    <h4>📄 文件信息</h4>
                    <p><strong>文件名:</strong> ${data.data.file_info.original_filename}</p>
                    <p><strong>文件大小:</strong> ${formatFileSize(data.data.file_info.file_size)}</p>
                    <p><strong>文件类型:</strong> ${data.data.file_info.file_extension}</p>
                </div>
                
                <div class="skills-section">
                    <div class="result-card">
                        <h4>🛠️ 技能详情</h4>
                        
                        <div class="skills-category">
                            <h4>编程语言 (${keyInfo.skills.programming_languages.length})</h4>
                            <div class="skills-list">
                                ${keyInfo.skills.programming_languages.map(skill => `<span class="skill-tag">${skill}</span>`).join('')}
                            </div>
                        </div>
                        
                        <div class="skills-category">
                            <h4>框架技术 (${keyInfo.skills.frameworks.length})</h4>
                            <div class="skills-list">
                                ${keyInfo.skills.frameworks.map(skill => `<span class="skill-tag">${skill}</span>`).join('')}
                            </div>
                        </div>
                        
                        <div class="skills-category">
                            <h4>数据库 (${keyInfo.skills.databases.length})</h4>
                            <div class="skills-list">
                                ${keyInfo.skills.databases.map(skill => `<span class="skill-tag">${skill}</span>`).join('')}
                            </div>
                        </div>
                        
                        <div class="skills-category">
                            <h4>开发工具 (${keyInfo.skills.tools.length})</h4>
                            <div class="skills-list">
                                ${keyInfo.skills.tools.map(skill => `<span class="skill-tag">${skill}</span>`).join('')}
                            </div>
                        </div>
                    </div>
                </div>
            `;
            
            // 原始内容标签
            document.getElementById('contentPreview').innerHTML = `
                <div class="result-card">
                    <h4>📝 解析出的文本内容</h4>
                    <div class="content-preview">${escapeHtml(data.data.raw_content)}</div>
                </div>
            `;
        }
        
        function displaySimpleResult(data) {
            document.getElementById('overviewContent').innerHTML = `
                <div class="result-card success">
                    <h3>✅ 简化版API解析成功</h3>
                    <p>使用简化版API只返回基本的文本内容</p>
                </div>
                
                <div class="result-card">
                    <h4>📄 文件信息</h4>
                    <p><strong>文件名:</strong> ${selectedFile.name}</p>
                    <p><strong>文件大小:</strong> ${formatFileSize(selectedFile.size)}</p>
                </div>
            `;
            
            document.getElementById('detailsContent').innerHTML = `
                <div class="result-card">
                    <h4>ℹ️ 简化版说明</h4>
                    <p>简化版API主要用于快速提取文本内容，不进行复杂的信息解析。</p>
                    <p>如需要详细的技能分析和信息提取，请使用完整版API。</p>
                </div>
            `;
            
            document.getElementById('contentPreview').innerHTML = `
                <div class="result-card">
                    <h4>📝 解析出的文本内容</h4>
                    <div class="content-preview">${escapeHtml(data.data.raw_content)}</div>
                </div>
            `;
        }
        
        function displayError(data) {
            document.getElementById('overviewContent').innerHTML = `
                <div class="result-card error">
                    <h3>❌ ${data.message}</h3>
                    ${data.error ? `<p><strong>错误代码:</strong> ${data.error}</p>` : ''}
                </div>
            `;
        }
        
        function showTab(tabName) {
            // 隐藏所有标签内容
            document.querySelectorAll('.tab-content').forEach(tab => {
                tab.classList.remove('active');
            });
            
            // 移除所有按钮的active类
            document.querySelectorAll('.tab-button').forEach(btn => {
                btn.classList.remove('active');
            });
            
            // 显示选中的标签
            document.getElementById(tabName + 'Tab').classList.add('active');
            event.target.classList.add('active');
        }
        
        function formatFileSize(bytes) {
            if (bytes === 0) return '0 Bytes';
            const k = 1024;
            const sizes = ['Bytes', 'KB', 'MB', 'GB'];
            const i = Math.floor(Math.log(bytes) / Math.log(k));
            return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
        }
        
        function escapeHtml(text) {
            const div = document.createElement('div');
            div.textContent = text;
            return div.innerHTML;
        }
    </script>
</body>
</html>
